using System;
using System.Data;
using System.Text;
using BrightFrame;
using AIM.Model;
using System.Collections.Generic;
namespace AIM.DAL
{
    public class ArchiveReportDAL
    {
        private DbProvider dbProvider = new DbProvider();

        public ArchiveReport GetModel(int archiveReportID)
        {
            ArchiveReport archiveReport = null;
            using (IDataReader dr = dbProvider.ExecuteDataReader("SELECT ArchiveReportID,ArchiveKindID,ReportName,ReportFile,ArchiveType FROM archive_report WHERE ArchiveReportID=?ArchiveReportID",
                dbProvider.CreateParameter("?ArchiveReportID", DbType.Int32, archiveReportID)))
            {
                if (dr.Read())
                {
                    archiveReport = new ArchiveReport
                    {
                        ArchiveReportID = Convert.ToInt32(dr["ArchiveReportID"]),
                        ArchiveKind = new ArchiveKind
                        {
                            ArchiveKindID = dr["ArchiveKindID"].ToString()
                        },
                        ReportName = dr["ReportName"].ToString(),
                        ReportFile = dr["ReportFile"].ToString(),
                        ArchiveType = dr["ArchiveType"].ToString()
                    };
                }
            }
            return archiveReport;
        }

        public List<ArchiveReport> QueryByArchiveKindID(string archiveKindID)
        {
            List<ArchiveReport> archiveReportList = new List<ArchiveReport>();
            using (IDataReader dr = dbProvider.ExecuteDataReader(@"
SELECT 
    ArchiveReportID,
    ArchiveKindID,
    ReportName,
    ReportFile,
    ArchiveType 
FROM archive_report 
WHERE ArchiveKindID=?ArchiveKindID",
                dbProvider.CreateParameter("?ArchiveKindID", DbType.AnsiString, archiveKindID)))
            {
                while (dr.Read())
                {
                    archiveReportList.Add(new ArchiveReport
                    {
                        ArchiveReportID = Convert.ToInt32(dr["ArchiveReportID"]),
                        ArchiveKind = new ArchiveKind
                        {
                            ArchiveKindID = dr["ArchiveKindID"].ToString()
                        },
                        ReportName = dr["ReportName"].ToString(),
                        ReportFile = dr["ReportFile"].ToString(),
                        ArchiveType = dr["ArchiveType"].ToString()
                    });
                }
            }
            return archiveReportList;
        }
    }
}

